package cn.sky1998.mango.common.exception.file;

import org.apache.tomcat.util.http.fileupload.FileUploadException;

import java.util.Arrays;

/**
 * 文件上传 误异常类
 *
 * @author tcy@1753163342@qq.com
 */
public class InvalidExtensionException extends FileUploadException {
  private static final long serialVersionUID = 1L;

  private final String[] allowedExtension;
  private final String extension;
  private final String filename;

  public InvalidExtensionException(String[] allowedExtension, String extension, String filename) {
    super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
    this.allowedExtension = allowedExtension;
    this.extension = extension;
    this.filename = filename;
  }

  public String[] getAllowedExtension() {
    return allowedExtension;
  }

  public String getExtension() {
    return extension;
  }

  public String getFilename() {
    return filename;
  }

  public static class InvalidImageExtensionException extends InvalidExtensionException {
    private static final long serialVersionUID = 1L;

    public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) {
      super(allowedExtension, extension, filename);
    }
  }

  public static class InvalidFlashExtensionException extends InvalidExtensionException {
    private static final long serialVersionUID = 1L;

    public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) {
      super(allowedExtension, extension, filename);
    }
  }

  public static class InvalidMediaExtensionException extends InvalidExtensionException {
    private static final long serialVersionUID = 1L;

    public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) {
      super(allowedExtension, extension, filename);
    }
  }
}
